home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C09 / Noinsitu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  887 b   |  45 lines

  1. //: C09:Noinsitu.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Removing in situ functions
  7.  
  8. class Rectangle {
  9.   int width, height;
  10. public:
  11.   Rectangle(int w = 0, int h = 0);
  12.   int getWidth() const;
  13.   void setWidth(int w);
  14.   int getHeight() const;
  15.   void setHeight(int h);
  16. };
  17.  
  18. inline Rectangle::Rectangle(int w, int h)
  19.   : width(w), height(h) {
  20. }
  21.  
  22. inline int Rectangle::getWidth() const {
  23.   return width;
  24. }
  25.  
  26. inline void Rectangle::setWidth(int w) {
  27.   width = w;
  28. }
  29.  
  30. inline int Rectangle::getHeight() const {
  31.   return height;
  32. }
  33.  
  34. inline void Rectangle::setHeight(int h) {
  35.   height = h;
  36. }
  37.  
  38. int main() {
  39.   Rectangle r(19, 47);
  40.   // Transpose width & height:
  41.   int iHeight = r.getHeight();
  42.   r.setHeight(r.getWidth());
  43.   r.setWidth(iHeight);
  44. } ///:~
  45.